// 引入mockjs
const Mock = require('mockjs')
// 获取 mock.Random 对象
// eslint-disable-next-line no-unused-vars
const Random = Mock.Random
var isCollect = false
// 使用mockjs模拟数据
Mock.mock('/register', (req) => {
    const list = {
        username: req.username,
        password: req.password,
        retcode: 0
    }
    return list
})
Mock.mock('/login', (req) => {
    const r = JSON.parse(req.body)
    console.log('/login:', req)
    if (r.username === '1' && r.password === '1') {
        const list = {
            username: req.username,
            password: req.password,
            retcode: 0
        }
        return list
    }
    return {retcode: 1}
})

Mock.mock('/show_paperpage_by_title_resource', (req) => {
    const list = {
        name: req.name
    }
    return list
})

Mock.mock('/show_indexpage', () => {
    const indexData = require('@/data/indexpage.json')
    const list = {
        data: indexData
    }
    return list
})

Mock.mock('/show_paperpage', () => {
    const paperData = require('@/data/paperpage.json')
    return paperData
})
Mock.mock('/show_techpage', (req) => {
    const techType = JSON.parse(req.body).type
    if (techType === '总体') {
        return require('@/data/tech.json')
    } else if (techType === '压气机') {
        return require('@/data/machine.json')
    } else {
        return require('@/data/fire.json')
    }
})

Mock.mock('/show_authorpage', (req) => {
    console.log('show_authorpage:', req)
    return require('@/data/authorpage.json')
})

Mock.mock('/show_frompage', (req) => {
    console.log('show_frompage:', req)
    return require('@/data/frompage.json')
})
//
Mock.mock('/show_institutionpage', (req) => {
    console.log('show_institutionpage:', req)
    const list = require('@/data/institutionpage.json')
    return list
})

Mock.mock('/get_user_paper_collect', () => {
    if (isCollect) {
        return {retcode: 1}
    } else {
        return {retcode: 0}
    }
})
Mock.mock('/collect', () => {
    isCollect = true
    return {retcode: 1}
})
Mock.mock('/collect_cancel', () => {
    isCollect = false
    return {retcode: 1}
})
